package com.mall.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mall.db.domain.Order;
import com.mall.db.service.OrderService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/system/oc")
public class OrderController extends BaseController<Order> {
  @Resource(name = "orderService")
    private OrderService os;

    @Override
    public Map<String, Object> find(Order order) {
        PageHelper.startPage(order.getPage(),order.getLimit());
        QueryWrapper<Order> qw=new QueryWrapper<>();
        List<Order> list= os.list(qw);
        PageInfo<Order> page=new PageInfo<>(list,order.getLimit());
        return this.findMap(page.getList(),page.getTotal());
    }
    @RequestMapping("/find1")
    public Map<String, Object> find1(Order order) {
        PageHelper.startPage(order.getPage(),order.getLimit());
        QueryWrapper<Order> qw=new QueryWrapper<>();
        qw.eq("state","待支付");
        List<Order> list= os.list(qw);
        PageInfo<Order> page=new PageInfo<>(list,order.getLimit());
        return this.findMap(page.getList(),page.getTotal());
    }
    @RequestMapping("/find2")
    public Map<String, Object> find2(Order order) {
        PageHelper.startPage(order.getPage(),order.getLimit());
        QueryWrapper<Order> qw=new QueryWrapper<>();
        qw.eq("state","待发货");
        List<Order> list= os.list(qw);
        PageInfo<Order> page=new PageInfo<>(list,order.getLimit());
        return this.findMap(page.getList(),page.getTotal());
    }
    @RequestMapping("/refundOrder")
    public Map<String, Object> refundOrder(Order order) {
        PageHelper.startPage(order.getPage(),order.getLimit());
        QueryWrapper<Order> qw=new QueryWrapper<>();
        qw.eq("state","已退款");
        List<Order> list= os.list(qw);
        PageInfo<Order> page=new PageInfo<>(list,order.getLimit());
        return this.findMap(page.getList(),page.getTotal());
    }
    @RequestMapping("/find3")
    public Map<String, Object> find3(Order order) {
        PageHelper.startPage(order.getPage(),order.getLimit());
        QueryWrapper<Order> qw=new QueryWrapper<>();
        qw.eq("state","已完成");
        List<Order> list= os.list(qw);
        PageInfo<Order> page=new PageInfo<>(list,order.getLimit());
        return this.findMap(page.getList(),page.getTotal());
    }
    @RequestMapping("/find4")
    public Map<String, Object> find4(Order order) {
        PageHelper.startPage(order.getPage(),order.getLimit());
        QueryWrapper<Order> qw=new QueryWrapper<>();
        qw.eq("state","待收货");
        List<Order> list= os.list(qw);
        PageInfo<Order> page=new PageInfo<>(list,order.getLimit());
        return this.findMap(page.getList(),page.getTotal());
    }
    @RequestMapping("/find5")
    public Map<String, Object> find5(Order order) {
        PageHelper.startPage(order.getPage(),order.getLimit());
        QueryWrapper<Order> qw=new QueryWrapper<>();
        List<String>stringList=new ArrayList<>();
        stringList.add("用户取消");
        stringList.add("订单超时");
        qw.in("state",stringList);
        List<Order> list= os.list(qw);
        PageInfo<Order> page=new PageInfo<>(list,order.getLimit());
        return this.findMap(page.getList(),page.getTotal());
    }
    @RequestMapping("/fahuo")
    public  Map<String,Object> fahuo(Order order){

        boolean b=os.updateById(order);
        return this.iud("发货",b,order);

    }
@Override
    public Map<String,Object>delete(Order order){
       boolean b=  os.removeById(order.getId());
        return this.iud("删除",b,order);
    }


}
